<template>
  <div class="dashboard-container">
    <div class="app-container">
      <el-card>
        <el-tabs>
          <el-tab-pane label="登录账户设置">

            <!-- 放置表单 -->
            <el-form ref="amendForm" label-width="120px" style="margin-left: 120px; margin-top:30px" :model="FormData" :rules="rules">
              <el-form-item label="姓名:" prop="username">
                <el-input v-model="FormData.username" style="width:300px" />
              </el-form-item>
              <el-form-item label="密码:" prop="password">
                <el-input v-model="FormData.password" style="width:300px" type="password" />
              </el-form-item>
              <el-form-item>
                <el-button type="primary" @click="submit">更新</el-button>
              </el-form-item>
            </el-form>
          </el-tab-pane>
          <el-tab-pane label="个人详情">
            <!-- <userInfo /> -->
            <!-- 动态显示组件 -->
            <components :is="page1" />
          </el-tab-pane>
          <el-tab-pane label="岗位信息">
            <!-- <jobInfo /> -->
            <components :is="page2" />
          </el-tab-pane>
        </el-tabs>
      </el-card>
    </div>
  </div>
</template>

<script>
import { saveUserDetailById } from '@/api/employees'
import { getUserId } from '@/api/user'
import userInfo from '@/views/employees/components/user-info.vue'
import jobInfo from '@/views/employees/components/job-info.vue'
export default {
  components: { userInfo, jobInfo },
  data() {
    return {
      page1: 'userInfo',
      page2: 'jobInfo',
      userId: this.$route.params.id,
      FormData: {
        username: '',
        password: ''
      },
      rules: {
        username: [{ required: true, message: '内容不能为空！', trigger: 'blur' },
          { min: 2, max: 6, message: '名字的长度在 2-6 位', trigger: 'blur' }],
        password: [{ required: true, message: '内容不能为空！', trigger: 'blur' }, { min: 6, max: 12, message: '密码的长度在 6-12 位', trigger: 'blur' }]
      }
    }
  },
  created() {
    this.getUserId()
  },
  methods: {
    //   获取用户信息 数据回显
    async getUserId() {
      const res = await getUserId(this.userId)
      this.FormData = { ...res, password: '' }
    //   console.log(res)
    },

    // 提交修改数据
    async submit() {
      // 校验表单
      await this.$refs.amendForm.validate()
      //   上传修改数据
      await saveUserDetailById(this.FormData)
      //   提醒用户
      this.$message.success('修改成功')
    }
  }
}
</script>

<style>

</style>
